package util;

/**
 * Clase para el manejo de fechas
 */
 import java.text.DateFormat;

 import java.text.ParseException;
 import java.text.SimpleDateFormat;

 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.Locale;

 public class Fecha {
     public Fecha() {
     }
     
     static public String GregorianCalendarToString(Calendar gc) 
     {
         DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT,
                                                    new Locale("es", "AR"));
         return df.format(gc.getTime());
     }
     
     static public GregorianCalendar StringToGregorianCalendar(String s) 
     {
         Date date=null;
         SimpleDateFormat df=new SimpleDateFormat("MM/dd/yyyy");
         try {
             date=df.parse(s);
             GregorianCalendar gc;
             gc =  new GregorianCalendar(date.getYear(),date.getMonth(),date.getDate());
             return gc;
         } catch (ParseException e) {
             // TODO
         }
        return null;
     }
         
     /**
      * Devuelve la cantidad de dias.
      * Si dateA > dateB, es positivo.
      * Si dateA < dateB, es negativo.
      **/
     public static long dateDiff(Date dateA,Date dateB) 
     {
         long diff = dateA.getTime() - dateB.getTime();
         return diff / (1000*60*60*24);
     }
     
     /**
      * Verifica si dateA es mayor a dateB.
      * Si dateA > dateB, TRUE.
      * Si dateA < dateB, FALSE.
      **/
     public static Boolean esMayor(Date dateA,Date dateB) 
     {
         long diff = dateA.getTime() - dateB.getTime();
         
         if (diff >= 0){
            return Boolean.TRUE;
         }
         
         return Boolean.FALSE;
     }
 }
